<template>
    <div>
<h1>编辑</h1>
<table class="table">
    <thead>
        <tr>
            <td>Kname</td>
            <td>
                <input type="text" v-model="data.Kname">
            </td>
        </tr>
        <tr>
            <td>Ktype</td>
            <td><select v-model="data.Ktype">
                    <option value="">请选择</option>
                    <option value="市场卡">市场卡</option>
                    <option value="次数卡">次数卡</option>
                    <option value="期限卡">期限卡</option>
                </select></td>
        </tr>
        <tr>
            <td>Kroom</td>
            <td><select v-model="data.Kroom">
                    <option value="">请选择</option>
                    <option value="门店1">门店1</option>
                    <option value="门店2">门店2</option>
                    <option value="门店3">门店3</option>
                </select></td>
            
        </tr>
        <tr>
            <td>times</td>
            <td>
                <span v-for="d in fuxuan">
                <input type="checkbox" v-model="box" :value="d">{{ d }}
            </span>
            </td>
        </tr>
        <tr>
            <td>havetimes</td>
            <td><input type="text" v-model="data.havetimes"></td>
        </tr>
        <tr>
            <td>price</td>
            <td><input type="text" v-model="data.price"></td>
        </tr>
        <tr>
            <td>total</td>
            <td><input type="text" v-model="data.total"></td>
        </tr>
        <tr>
            <td>Kstatus</td>
            <td><select v-model="data.Kstatus">
                    <option value="">请选择</option>
                    <option value="下架">下架</option>
                    <option value="上架">上架</option>
                </select></td>
        </tr>
        <tr>
            <td>Imgurl</td>
            <td><input type="text" v-model="data.Imgurl"></td>
        </tr>
        <tr>
            
            <td colspan="2"><input type="button" value="编辑" class="btn btn-success" @click="tianj"></td>
        </tr>
        
    </thead>
    <tbody></tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();


const fuxuan = ref(["周一","周二","周三","周四","周五","周六","周日"])
const box = ref([])


const data = ref({
  "id": 0,
  "Kname": "",
  "Ktype": "",
  "Kroom": "",
  "times": "",
  "havetimes": "",
  "price": 0,
  "total": 0,
  "Kstatus": "",
  "Imgurl": "",
  "IsDel": 0
});
onMounted(() => {
    fant();
});

const fant =()=>{
    var mid = route.query.id
    axios.get("https://localhost:7111/api/Base/FTone",{params:{id:mid}}).then(res=>{
        data.value=res.data;
        box.value=data.value.times.split(",");
    })
}


const tianj=()=>{
    data.value.times=box.value.toString()
    axios.post("https://localhost:7111/api/Base/Uptone",data.value).then(res=>{
        if(res.data==1)
        {
            alert("编辑成功");
            location.href="/";
        }
        else{
            alert("编辑失败");
            
        }
    })
}


</script>

<style scoped>

</style>